/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rafkind.raytracer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;

/**
 *
 * @author drafkind
 */
public class Main {

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    final Scene scene = SceneLoader.loadFromLocalResource("com/rafkind/raytracer/scene.xml");
    
    SwingUtilities.invokeLater(new Runnable(){
      public void run() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(new BorderLayout());

        final ViewPort vp = new ViewPort();
        frame.getContentPane().add(vp, BorderLayout.CENTER);

        Box vbox = Box.createVerticalBox();
        JSlider sunSlider = new JSlider(JSlider.VERTICAL, 0, 23, 0);
        vbox.add(sunSlider);
        JButton renderButton = new JButton("Render");
        vbox.add(renderButton);
        frame.getContentPane().add(vbox, BorderLayout.EAST);

        final JProgressBar progress = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
        frame.getContentPane().add(progress, BorderLayout.SOUTH);


        renderButton.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e) {
            vp.setImage(scene.render(progress));
          }
        });
        
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.pack();

        frame.setBounds((d.width-640)/2, (d.height-480)/2, 640, 480);
        frame.setVisible(true);
      }
    });
  }
}